Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
Ext.onReady(function() { 
	//定义树的事件响应函数
	function _treeonClick(node,evt){
		function sucloadjs(){
			var tab = center.getComponent(node.id);
			if (!tab) {
				eval("var tab = new "+node.id+"();");
				center.add(tab);
				
			}
			center.setActiveTab(tab);
			tab.doLayout(true);//用于重新计算新建panel的size，否则该panel的有些layout没有size的计算基准，不显示。
		}
		function failoadjs(){
			Ext.Msg.alert('错误', '连接失败！请稍后再试。');
		}
		evt.stopEvent(); 
		if(node.leaf){
			dLoadJs(node.attributes.loadjs,sucloadjs,failoadjs)
		}
	}//end function _treeonClick

	//构建 west 面板 用于显示系统菜单
	var west = new Ext.tree.TreePanel({
			region:'west',
			el:'west-div',
			id:'west-div',
			title:'系统菜单',
			//ctCls:'nav',
			hideCollapseTool:false,
			collapsible:true,
			lines:false,
			width:150,
			autoScroll:true,

			rootVisible:false,
			loader:new Ext.tree.TreeLoader({
				dataUrl:'js/navTree.json',
				baseAttrs: { expandable: false } //添加 Node Class 属性
				}),
			root:new Ext.tree.AsyncTreeNode({
				
			})
			
			
	});//end var west

	//注册系统菜单的点击事件
	west.on('click',_treeonClick);

	//构建 head 面板 用于显示台头
	var north = new Ext.Panel({
			region:'north',
			//el:'north-div',
			id:'north-div',
			height:60,
			layout:'fit',
			frame : true,
			items:[{
				id:'siteLogo',
				layout: 'column',
				items:[{
					columnWidth:.4,
					height:60,
					width:120,
					html:'<h1>织慧零售管理系统</h1>'
				},{
					columnWidth:.2,
					html:'<h1 align=right>终端：'+jsCfgData.UserMessage.terminal_name+'('+jsCfgData.UserMessage.terminal_id+')</h1>'
				},{
					columnWidth:.2,
					html:'<h1 align=right>登陆用户:'+jsCfgData.UserMessage.USERNAME+'</h1>'
				},{
					columnWidth:.2,
					html:'<h1 align=right><a href=index.php?controller=Login&action=logout>退出</a>'+'</h1>'
				}]			
			}]

	});//end var north

	//north.innerHTML = '<h1 class="x-panel-header">织慧零售管理系统</h1>';

	//构建 south 面板 用于显示页脚
	var south = new Ext.BoxComponent({
		region:'south',
		id:'south-div',
		el:'south-div',
		height: 25
		
	});//end var south
 
	//构建 center 面板 用于显示功能区
	var center = new Ext.TabPanel({
			region:'center',
			deferredRender:false,
			activeTab:0,
			resizeTabs:true,
			minTabWidth: 115,
			tabWidth:135,
			enableTabScroll:true,
			items:[{
				id:'welcome',
				title:'欢迎页面',
				closable:false,
				html: 'Wellcome'
			}]
		});

	//构建 视图 显示整个网站
	 new Ext.Viewport({
			layout:'border',
			monitorResize:true,
			items:[north,center,west,south]
		
	 });//end new Ext.Viewport
});//end Ext.onReady